﻿using System.IO;
using System.Web.Mvc;
using ConfigExplorer.Model;
using ConfigExplorer.Web.DocsReaders;

namespace ConfigExplorer.Web.Controllers
{
    public class AssetsController : Controller
    {
        public ActionResult Favicon()
        {
            return new HttpNotFoundResult();
        }

        public ActionResult Map(string applicationName, string artifactid, string version)
        {
            Manifest mainfest = ManifestReader.GetCurrentManifest(version, Request.PhysicalApplicationPath);

            string filePath = Path.Combine(Path.Combine(mainfest.Path, "Assets/Maps"), string.Concat(artifactid, ".gz"));

            Response.AppendHeader("Content-Encoding", "gzip");

            return File(filePath, "text/xml");
        }

        public ActionResult Schema(string artifactid, string version)
        {
            Manifest mainfest = ManifestReader.GetCurrentManifest(version, Request.PhysicalApplicationPath);

            string filePath = Path.Combine(Path.Combine(mainfest.Path, "Assets/Schemas"), string.Concat(artifactid, ".gz"));

            Response.AppendHeader("Content-Encoding", "gzip");

            return File(filePath, "text/xml");
        }

        public ActionResult Orchestration(string artifactid, string version)
        {
            Manifest mainfest = ManifestReader.GetCurrentManifest(version, Request.PhysicalApplicationPath);

            return File(Path.Combine(Path.Combine(mainfest.Path, "Assets/Overview"), string.Concat(artifactid, ".jpg")), "image/jpeg");
        }

        public ActionResult OrchestrationThumb(string artifactid, string version)
        {
            Manifest mainfest = ManifestReader.GetCurrentManifest(version, Request.PhysicalApplicationPath);

            return File(Path.Combine(Path.Combine(mainfest.Path, "Assets/Overview"), string.Concat(artifactid, "_thumb.jpg")), "image/jpeg");
        }
    }
}